from gi.repository import GLib

import dbus
import dbus.mainloop.glib

import subprocess

class SignalListener:
    def __init__(self):
        bus = dbus.SessionBus()
        proxy = bus.get_object("com.example.TestService","/com/example/TestService/object")
        proxy.connect_to_signal("HelloSignal", 
                                self.Switch_Page,  # callback
                                dbus_interface="interface.TestService", 
                                arg0="Hello")  # String argument matching

    def Switch_Page(self, message):
        print ("Received signal (by connecting using remote object) and it says: " + message)
        subprocess.call("zenity --info --text='response by signal listener: {}'".format(message), shell=True)


if __name__ == "__main__":
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    SignalListener()

    loop = GLib.MainLoop()
    print("Running example signal emitter service.")
    loop.run()